//自定义异常

//受查异常，继承于Exception
class MyException extends Exception{
    public MyException(String message) {
        super(message);
    }
}

//非受查异常，继承于RuntimeException
class MyException2 extends RuntimeException{
    public MyException2(String message) {
        super(message);
    }
}

public class TestDemo3 {

    //受查异常需要try catch包裹或者手动throws抛出
    public static void func1(int x) {
        try {
            if(x == 0) {
                throw new MyException("heihei");
            }
        }catch (MyException e) {
            e.printStackTrace();
        }
    }

    public static void func2(int x) throws MyException{
        if(x == 0) {
            throw new MyException("haha");
        }
    }

    //非受查异常不用，但是会被jvm处理
    public static void func3(int x){
        if(x == 0) {
            throw new MyException2("heihei");
        }
    }

    public static void main(String[] args){
        func1(0);
    }
}
